package com.test.study.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Logger;


/**
 * 使用装饰着设计模式 增强 close 方法
 * @author huyong
 *
 */
public class MyConnectionWrapper extends ConnectionWrapper {
	private static final Logger LOGGER=Logger.getLogger(MyConnectionWrapper.class.getCanonicalName());
	// 需要被增强的对象
	private Connection connection;
	private List<Connection> connections;

	public MyConnectionWrapper(Connection connection,List<Connection> connections) {
		super(connection);
		this.connection=connection;
		this.connections=connections;
	}
	//增强close 方法
	@Override
	public void close() throws SQLException {
		
		//归还连接
		connections.add(connection);
		LOGGER.info("back after dataSource pool size ==> "+connections.size());
	}

}
